﻿using Newtonsoft.Json;
using SenFangKaoHe_MVC.Models.Entity;
using SenFangKaoHe_MVC.Models.ViewModel;
using SqlSugar;
using SqlSugar.SplitTableExtensions;
using System.Diagnostics;

namespace SenFangKaoHe_MVC.Services
{
    public class LianXiServices
    {
        private readonly SqlSugarClient db;
        public LianXiServices(SqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<TempShiJuan> getMoNiCuoTi(string tkmc,string ctids, string ctdas,int fenzhi,int chengji)
        {
            TempShiJuan sjct = new TempShiJuan();

            sjct.Id = -1;
            sjct.XingMing = "模拟用户";
            sjct.KaoHeMingCheng = tkmc+"模拟考核";
            sjct.KaoHeFanWei = tkmc;
            sjct.FenZhi = fenzhi;
            sjct.ChengJi = chengji;

            int[] ctid = new int[ctids.Split(",").Length];
            string[] ctda = new string[ctdas.Split(",").Length];
            for (int t = 0; t < ctid.Length; t++)
            {
                ctid[t] = Convert.ToInt32(ctids.Split(",")[t]);
            }
            for (int t = 0; t < ctda.Length; t++)
            {
                ctda[t] = ctdas.Split(",")[t];
            }

            List<TempShiJuanKaoTi> cts = new List<TempShiJuanKaoTi>();
            for (int i = 0; i < ctid.Length; i++)
            {
                List<string> xx = new List<string>();
                tikukaoti st = await new TiKuServices(db).getTiKuKaoTi(Convert.ToInt32(ctid[i]));
                for (int a = 0; a < st.xuanxiang.Split(';').Length; a++)
                {
                    xx.Add(st.xuanxiang.Split(";")[a]);
                }
                int fz = 0;
                switch (st.tixing)
                {
                    case 1:
                        fz = 0;
                        break;
                    case 2:
                        fz = 3;
                        break;
                    case 3:
                        fz = 4;
                        break;
                    case 4:
                        fz = 3;
                        break;
                }
                TempShiJuanKaoTi ct = new TempShiJuanKaoTi();
                ct.Id = i + 1;
                ct.TiMu = st.timu;
                ct.XuanXiang = xx;
                ct.BiaoZhunDaAn = st.daan;
                ct.DuiYuanDaAn = ctda[i];
                ct.TiXingId = st.tixing;
                ct.FenZhi = fz;
                cts.Add(ct);
            }
            sjct.ShiTi = cts;


            return sjct;
        }
    }
}
